package com.wnxy.controller;

import com.wnxy.utils.TokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 林夕
 * @since 2023-03-18 11:05:47
 */
@RestController
@RequestMapping("/jwt")
public class JwtController {
    @Autowired
    StringRedisTemplate stringRedisTemplate;

    @RequestMapping("saveToken")
    public String saveToken(String key1, String value, HttpServletResponse response){
        //将信息保存在token中
        String token = TokenUtil.createUserToken(key1, value, response, stringRedisTemplate);
        return token;
    }

    @RequestMapping("getValue")
    public String getValue(String key2, HttpServletRequest request, HttpServletResponse response){
        String account = TokenUtil.getUserAccount(key2, request);
        TokenUtil.deleteUserToken(response,request,stringRedisTemplate);
        return account;
    }

}
